package cn.whitecao.agent.plugin.jdbc.handler;


import cn.whitecao.agent.core.handler.HandlerLoader;
import cn.whitecao.agent.core.handler.PluginAopHandler;

import net.bytebuddy.asm.Advice;


/**
 * @author : BashfulHuang
 **/
public class JdbcInterceptor {

    @Advice.OnMethodEnter()
    public static void enter(
            @Advice.Local("pluginAopHandler") PluginAopHandler pluginAopHandler,
            @Advice.Origin("#m") String methodName,
            @Advice.Origin("#t") String className,
            @Advice.This Object oThis) {
        pluginAopHandler = HandlerLoader.load("cn.whitecao.agent.plugin.jdbc.handler.AopHandler");
        pluginAopHandler.before(className,methodName,null,oThis);
    }


    @Advice.OnMethodExit(onThrowable = Throwable.class)
    public static void exit(
            @Advice.Local("pluginAopHandler") PluginAopHandler pluginAopHandler,
            @Advice.Origin("#m") String methodName,
            @Advice.Origin("#t") String className,
            @Advice.AllArguments Object[] args,
            @Advice.This Object oThis,
            @Advice.Thrown Throwable t) {
        pluginAopHandler.after(methodName,className,args,null,oThis, t);
    }

}
